Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

dettle

Package Overview
Dependencies
Maintainers
0
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dettle

A tiny fully-featured debounce and throttle implementation.

  • 1.0.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
51K
increased by23.54%
Maintainers
0
Weekly downloads
 
Created
Source

Dettle

A tiny fully-featured debounce and throttle implementation.

Install

npm install --save dettle

Usage

import {debounce, throttle} from 'dettle';

const fn = () => console.log ( 'Fired!' );

// Debouncing
// The following options are supported:
// `leading`: whether the function should be called when the timeout is created, defaults to `false`
// `trailing`: whether the function should be called when the timeout expires, defaults to `true`
// `maxWait`: the maximum amount of time that can pass before the function is called, defaults to `Infinity`

const debounced = debounce ( fn, 1000, {
  leading: false,
  trailing: true,
  maxWait: Infinity
});

debounced (); // Schedule function for execution
debounced (); // Re-schedule function for execution

debounced.flush (); // Execute the function immediately, if there's a scheduled execution
debounced.cancel (); // Cancel the scheduled execution

// Throttling
// The API for throttling is basically the same, except that:
// - `leading`: is `true` by default rather than `false`
// - `maxWait`: is set implicitly for you to be equal to the wait time

const throttled = throttle ( fn, 1000, {
  leading: true,
  trailing: true
});

throttled (); // Call the function immediately
throttled (); // Schedule function for execution

throttled.flush (); // Execute the function immediately, if there's a scheduled execution
throttled.cancel (); // Cancel the scheduled execution

License

MIT © Fabio Spampinato

Keywords

FAQs

Package last updated on 30 Jun 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc